<?php
require_once 'BaseController.php';

/**
 * 検索条件登録画面コントローラクラス<br />
 *
 * @package apamanshop
 * @author
 * @copyright　
 */
class Mypage_SearchlistController extends Mypage_BaseController
{
	/**
	 * インデックスアクション
	 *
	 * @access public
	 * @return void
	 */
	public function indexAction()
	{
		//ログインチェック
		$this->checkLogin();

        //表示テンプレートパス設定
        $this->_display_path = APPLICATION_PATH . '/modules/mypage/views/scripts/common.tpl';

        //=====表示用共通パラメータ設定=====
		$this->setCommonParams();

		//=====hiddenタグ生成=====
		if (!empty($this->_params['PrefCd'])) $this->_hiddenParams['PrefCd'] = $this->_params['PrefCd'];
		if (!empty($this->_params['CityCd'])) $this->_hiddenParams['CityCd'] = $this->_params['CityCd'];
		if (!empty($this->_params['TownCd'])) $this->_hiddenParams['TownCd'] = $this->_params['TownCd'];
		if (!empty($this->_params['RailCd'])) $this->_hiddenParams['RailCd'] = $this->_params['RailCd'];
		if (!empty($this->_params['StCd']))   $this->_hiddenParams['StCd']   = $this->_params['StCd'];
		if (!empty($this->_params['SrhKbn'])) $this->_hiddenParams['SrhKbn'] = $this->_params['SrhKbn'];
		if (!empty($this->_params['SrhType'])) $this->_hiddenParams['SrhType'] = $this->_params['SrhType'];
		$this->_data['hiddenTag'] = Apm_Util::generateHiddenTag($this->_hiddenParams);
        //=====onload時用POST検索条件パラメータ生成=====
        $this->makeOnloadPostParams($this->_params);
		// モデルインスタンス生成
		// 外部モデル呼び出し設定
		$loader = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Rstobi',
			'basePath' => APPLICATION_PATH . '/modules/rstobi',
		));
		$model_menu           = new Mypage_Model_Menu();
		$model_user_info      = new Mypage_Model_MakeSideMenu();
		$model_recommend      = new Rstobi_Model_BknRecommend();		// レコメンド

		// メタタグ設定
		//$this->addMetaJs('/js/common/thickbox.js');
		$this->addMetaJs('/js/common/photo.js');
		//$this->addMetaJs('/js/mypage/list.js');
		$this->addMetaJs('/js/search/list.js');
		//$this->addMetaJs('/js/search/jquery-ui-1.7.1.custom.min.js', array('charset' => 'utf-8'));
		//$this->addMetaJs('/js/search/selectToUISlider.jQuery.js', array('charset' => 'utf-8'));
		//$this->addMetaJs('/app/js/mypage/searchlist.js');
		$this->addMetaJs('/app/js/Rstobi_mypage.js');
		$this->addMetaJs('/app/js/jquery.lazyload.mini.js');
//		$this->addMetaJs('/app/js/rstdtl/bukendtl.js');

		$this->addMetaCss('/css/mypage/mypage.css');
		$this->addMetaCss('/css/search/search.css');
		$this->addMetaCss('/css/search/searchdetail.css');
		$this->addMetaCss('/css/search/ui.slider.extras.css');
		$this->addMetaCss('/css/search/jquery-ui-1.7.1.custom.css');
		
		$this->addMetaCss('/common_new/css/sub.css' ,array('media' => 'all'));
		$this->addMetaCss('/common_new/css/common.css' ,array('media' => 'all'));

		// eID取得
		$cunnrentEId = $this->getCurrentUserEid();

		//uid設定
		$userList = $model_menu->getUId($cunnrentEId);
		// ユーザID設定
		$this->_params['Uid'] = $userList[0]['M92_USER_CD'];
		//ユーザＩＤからheyaCdを取得
		$this->_params['HeyaCd'] = $model_user_info->getHeyaCd($this->_params['Uid']);

		if (Apm_Otheritems::IsNullOrEmpty($this->_params['HeyaCd']))
		{
			//部屋コードがからの場合はダミーの値を設定しておく
			$this->_params['HeyaCd'] = "-1";
		}

		//サイドメニュー
		$this->_data['search_sid'] = $this->_params['sid'];
		$this->setSideMenu($this->_params['Uid']);

		//===== レコメンド検索 =====
		// レコメンド物件情報取得
		$this->_data['recommend'] = $model_recommend->getRecommendList($this->_params);
		// 表示用にコンバート
		$this->_data['recommend'] = $model_recommend->convertRecommendList($this->_data['recommend']);
		// レコメンドブロック生成
		$this->_data['recommend_block'] = $this->_recommend_helper->getBlock($this->_data);

		//=====表示=====
		//ブロック設定
		$this->setBlock($this->_searchlist_helper, $this->_js_joukenIns_helper);
		//表示
        $this->display($this->_display_path);
	}

	/**
	 * 検索条件検索結果画面の共通パラメータ設定
	 *
	 */
	private function setCommonParams()
	{
        //=====タイトル=====
		$this->setTitle('賃貸情報アパマンショップ[マイページ]');

		//=====タイトルバー設定=====
		$this->setContentsTitle('マイページ&nbsp;&gt;&gt;&nbsp;お気に入り物件一覧', '');

		//=====パンくず設定=====
		$this->_breadcrumb->reset();
        $this->_breadcrumb->add(Apm_Config_Search::BREADCRUMB_TOP, $this->_baseurl);
        $this->_breadcrumb->add('マイページ', $this->_baseurl . 'mypage/menu');
        $this->_breadcrumb->add('検索条件登録', $this->_sslurl . 'mypage/searchlist');
        $this->setBreadCrumb($this->_breadcrumb->generateBreadcrumb());
	}

	/**
	 * onload時用POSTパラメータ生成
	 *
	 */
	private function makeOnloadPostParams($params)
	{
		$p = "";
		foreach ($params as $key => $value) {
			if (is_array($value))
			{
				for ($i = 0; $i < count($value); $i++)
				{
					$p .= "&" . $key . "[" . $i . "]=" . $value[$i];
				}
			}
			else
			{
				$p .= "&" . $key . "=" . $value;
			}
		}
		$p = substr($p, 1);
		$this->_data["onloadPostParams"] = $p;
	}
}
?>
